package org.osomit.sacct.builder;

import org.osomit.sacct.entity.ApplicationAccountRecordSet;
import org.osomit.sacct.entity.ApplicationAccountRecord;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 * 
 * Date: Jul 1, 2009
 */
public class ApplicationAccountRecordSetBuilder extends BaseBuilder<ApplicationAccountRecordSet>{

    public ApplicationAccountRecordSet build(Object object) {
        
        if (object != null) {
            ApplicationAccountRecordSet set = new ApplicationAccountRecordSet();
            Map map = (Map) object;
            List list = (List) map.get(ApplicationAccountRecordSet.RECORDS);
            if(list != null && list.size() > 0){
                List<ApplicationAccountRecord> records = new ArrayList<ApplicationAccountRecord>();
                ApplicationAccountRecordBuilder builder = new ApplicationAccountRecordBuilder();
                for(Object obj: list){
                    ApplicationAccountRecord record = builder.build(obj);
                    records.add(record);
                }

                set.setRecords(records);
            }

            return set;
        }

        return null;
    }

}
